<?php
/***********************************************************
	Filename: langconfig.php
	Note	: 重新读取语言模块
	Version : 3.0
	Author  : qinggan
	Update  : 2009-12-22
***********************************************************/
class lang_m extends Model
{
	function __construct()
	{
		parent::Model();
	}

	function lang_m()
	{
		$this->__construct();
	}

	function get_one($id)
	{
		if(!$id)
		{
			return false;
		}
		$sql = "SELECT * FROM ".$this->db->prefix."lang WHERE langid='".$id."'";
		return $this->db->get_one($sql);
	}

	//读取语言包信息
	function get_list()
	{
		$sql = "SELECT * FROM ".$this->db->prefix."lang ORDER BY taxis ASC,langid ASC";
		return $this->db->get_all($sql);
	}

	//存储数据
	function save($data,$id=0)
	{
		if($id)
		{
			$this->db->update_array($data,"lang",array("langid"=>$id));
			return true;
		}
		else
		{
			$insert_id = $this->db->insert_array($data,"lang");
			return $insert_id;
		}
	}

	//存储变量和值
	function lang_list($langid)
	{
		if(!$langid)
		{
			return false;
		}
		$sql = "SELECT * FROM ".$this->db->prefix."lang_msg WHERE langid='".$langid."' ORDER BY var ASC";
		return $this->db->get_all($sql);
	}

	//存储数据
	function save_m($data,$id=0)
	{
		if($id)
		{
			$this->db->update_array($data,"lang_msg",array("id"=>$id));
			return true;
		}
		else
		{
			$insert_id = $this->db->insert_array($data,"lang_msg");
			return $insert_id;
		}
	}

	//删除值数据
	function del_m($id)
	{
		if(!$id)
		{
			return false;
		}
		$sql = "DELETE FROM ".$this->db->prefix."lang_msg WHERE id='".$id."'";
		return $this->db->query($sql);
	}

	//删除语言包
	function del($id)
	{
		if(!$id)
		{
			return false;
		}
		$sql = "DELETE FROM ".$this->db->prefix."lang WHERE langid='".$id."'";
		$this->db->query($sql);
		$sql = "DELETE FROM ".$this->db->prefix."lang_msg WEHRE langid='".$id."'";
		$this->db->query($sql);
		return true;
	}

	function set_status($id,$status=0)
	{
		$sql = "UPDATE ".$this->db->prefix."lang SET status='".$status."' WHERE langid='".$id."'";
		return $this->db->query($sql);
	}

	function set_default($id)
	{
		$sql = "UPDATE ".$this->db->prefix."lang SET ifdefault='0' WHERE ifdefault='1'";
		$this->db->query($sql);
		$sql = "UPDATE ".$this->db->prefix."lang SET ifdefault='1' WHERE langid='".$id."'";
		$this->db->query($sql);
		return true;
	}

	//检测变量名是否重复
	function chk_msg($var,$langid="zh",$ltype="all",$id=0)
	{
		$sql = "SELECT * FROM ".$this->db->prefix."lang_msg WHERE var='".$var."' ";
		$sql.= " AND langid='".$langid."' ";
		if($id)
		{
			$sql.= " AND id!='".$id."' ";
		}
		if($ltype == "www")
		{
			$sql.= " AND (ltype='www' OR ltype='all') ";
		}
		elseif($ltype == "admin")
		{
			$sql.= " AND (ltype='admin' OR ltype='all') ";
		}
		$rs = $this->db->get_one($sql);
		return $rs;
	}

}
?>